import response from "mock/response";
import Mock from "mockjs";
import { MockMethod } from "vite-plugin-mock";

export default [
  {
    url: "/api/types",
    method: "get",
    response: () => {
      return {
        code: 200,
        message: "ok",
        data: [
          {
            key: "1",
            value: "AAA",
          },
          {
            key: "2",
            value: "BBB",
          },
          {
            key: "3",
            value: "CCC",
          },
          {
            key: "4",
            value: "DDD",
          },
        ],
      };
    },
  },
  {
    url: "/api/multiple-list",
    method: "get",
    response: () => {
      const list = Mock.mock({
        "list|7": [
          {
            id: "@id",
            title: "2022-2023学年第二学期第一周周赛积分发放",
            type: {
              "id|+1": [100, 200, 300, 400],
              "typeName|+1": ["活动积分", "竞赛积分", "签到积分"],
            },
            people: "@integer(10, 20)",
            operator: {
              id: "@id",
              userName: "@cname",
              userNo: "20200700" + "@integer(30101, 30630)",
              userGender: '@pick(["男", "女"])',
              userAvatar:
                "https://img0.baidu.com/it/u=4132488213,1989687409&fm=253&fmt=auto&app=138&f=JPEG?w=200&h=200",
              userTel: "13712345678",
              userClass: "2020级软件工程5班",
              userRole: '@pick(["管理员", "普通成员"])',
              userRegisterTime: "@datetime",
              userCurPoint: "@integer(100, 999)",
              userCurStatus: '@pick("正常", "禁止")',
            },
            createTime: "2023-4-10 20:23:45",
            status: "@integer(0,1)",
          },
        ],
      });
      return response(list.list);
    },
  },
  {
    url: "/api/get-member-point",
    method: "get",
    response: () => {
      const points = [0, 0, 0, 0];
      const records = Mock.mock({
        "list|10": [
          {
            createTime: "2023-04-10 20:23:45",
            changeType: {
              "id|+1": [0, 1],
              "text|+1": ["加分", "扣分"],
            },
            changePoint: "@integer(10,20)",
            type: {
              "id|+1": [100, 200, 300],
              "typeName|+1": ["活动积分", "竞赛积分", "签到积分"],
            },
            operator: {
              id: "@id",
              userName: "@cname",
            },
          },
        ],
      });
      const totalPoint = records.list.reduce((sum: number, item: any) => sum + item.changePoint, 0);
      records.list.forEach((item: any) => {
        const index = item.type.id / 100 - 1;
        points[index] += item.changePoint;
      });
      const member = Mock.mock({
        id: "@id",
        userName: "@cname",
        userNo: "20200700" + "@integer(30101, 30630)",
        userTel: "13712345678",
        userClass: "2020级软件工程5班",
        userPoints: [
          {
            id: 100,
            typeName: "活动积分",
            pointValue: points[0],
          },
          {
            id: 200,
            typeName: "竞赛积分",
            pointValue: points[1],
          },
          {
            id: 300,
            typeName: "签到积分",
            pointValue: points[2],
          },
        ],
        userTotalPoint: totalPoint,
        userPointChangeRecords: records.list,
      });
      return response(member);
    },
  },
] as MockMethod[];
